package com.westcom.secritycheck.SecurityGate.impl;

import com.westcom.secritycheck.SecurityGate.SecurityGate;
import com.westcom.secritycheck.WaitingLine.IWaitingLine;
import com.westcom.secritycheck.bean.OperationException;
import com.westcom.secritycheck.bean.Passenger;
import com.westcom.secritycheck.constants.Constants;
import com.westcom.secritycheck.constants.Utils;

import java.util.Random;

/*
 * auth:zoupeng
 * date:20180904
 * */
public class  RandomSecrityGate extends SecurityGate
{
    private Random seed = new Random();
    public RandomSecrityGate(int checkPeriod, IWaitingLine line) throws OperationException
    {
        super(checkPeriod,line);
    }
    @Override
    public boolean check(Passenger p)
    {
        return seed.nextDouble() >= Constants.PROBABILITY_OF_PASS_GATE?false:true;
    }

    @Override
    public void onPass(Passenger p)
    {
        Utils.printLog(p.toString(),"passed","line size:"+line.size());
        line.print();
    }

    @Override
    public void onDenied(Passenger p)
    {
        Utils.printLog(p.toString(),"denied,add to line");
        line.push(p);
    }
}
